library(tidyverse)
library(plotly)
library(p8105.datasets)
Load data
data(instacart)
Filter data
instacart =
instacart |>
select (department, aisle, order_hour_of_day, order_number, days_since_prior_order)
instacart |>
count(department) |>
filter(department != "missing") |>
mutate(department = fct_reorder(department, n)) |>
plot_ly (x = ~department, y = ~n, color = ~department,
type = "bar", colors = "viridis") |>
layout(
xaxis = list(title = "Department"),
yaxis = list(title = "Number of Items")
)
instacart |>
filter(department != "missing") |>
mutate(department = fct_reorder(department, order_hour_of_day)) |>
plot_ly(x = ~department, y = ~order_hour_of_day, color = ~department,
type = "box", colors = "viridis") |>
layout(
xaxis = list(title = "Department"),
yaxis = list(title = "Order Hour of Day")
)